package com.sky.controller.admin;

import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author : jiang
 * @date : 2023/10/24 8:58
 */
@RestController("adminOrderController")
@RequestMapping("/admin/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    /**
     * 订单搜索
     * @param ordersPageQueryDTO
     * @return
     */
    @GetMapping("/conditionSearch")
    public Result<PageResult> page(OrdersPageQueryDTO ordersPageQueryDTO){
        PageResult page = orderService.page(ordersPageQueryDTO);
        return Result.success(page);
    }

    /**
     * 商家端查看订单详情
     * @param id
     * @return
     */
    @GetMapping("/details/{id}")
    public Result<OrderVO> getOrdersDetails(@PathVariable Long id){
        OrderVO orderVo = orderService.getOrdersDetails(id);
        return Result.success(orderVo);
    }

    /**
     * 统计各类订单数量
     * @return
     */
    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> getOrderStatistics(){
        OrderStatisticsVO orderStatisticsVO = orderService.getOrdersStatistics();

        return Result.success(orderStatisticsVO);
    }

    /**
     * 完成订单
     * @param id
     * @return
     */
    @PutMapping("/complete/{id}")
    public Result complete(@PathVariable Long id){
        orderService.complete(id);
        return Result.success();
    }

    /**
     * 接单
     * @param orders
     * @return
     */
    @PutMapping("/confirm")
    public Result comFirm(@RequestBody Orders orders){
        orderService.conFirm(orders);
        return Result.success();
    }

    /**
     * 拒单
     * @return
     */
    @PutMapping("/rejection")
    public Result rejection(@RequestBody Orders orders){
        orderService.rejection(orders);
        return Result.success();
    }

    /**
     * 派送订单
     * @param id
     * @return
     */
    @PutMapping("/delivery/{id}")
    public Result delivery(@PathVariable Long id){
        orderService.delivery(id);
        return Result.success();
    }
}
